import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

import org.korifey.ffalg.NumberTheory;
import org.korifey.ffalg.Probabilities;


public class Problem21 {
	
	public static void main(String[] args) {
		System.out.println(solve());
	}
	static int n = 10000;	
	private static int[] propDivSum = new int[n];
	
	public static int propDivSum(int x) {
		if (x >= propDivSum.length || propDivSum[x] == 0) {
			int res = 0;
			for (long i=1; i<=x/2; i++) {
				if (x %i ==0) res+=i;
			}
			if (x < propDivSum.length) propDivSum[x] = res;
			else return res;
		}
		return propDivSum[x];
	}
		
	public static long solve() {
		long res = 0;
		for (int i=1; i<n; i++) {
			if (propDivSum(propDivSum(i)) == i && propDivSum(i) != i) {
				System.out.println(i);
				res += i;
				//if 	(propDivSum(i) < n && propDivSum(i) > i) res+= propDivSum(i); 
			}
		}
		return res;
	}
	
}
